<?php $this->load->view('layout/header');?>
<div class="supplier-content-page">
    <div class="product-test-h5">
        <ul class="breadcrumb">
            <li><a href="javascript:;">商品管理</a></li>
            <li class="active"><a href="javascript:;">编辑分润模板</a></li>
        </ul>
        <p>所有比率与手续费率之和应为100</p>
        <div class="product-alls">
            <div class="product-fonter">新增分润模板</div>
            <form class="form-horizontal" action="<?php echo site_url('tourismprofitrate/editPost');?>" method="post" id="tourismprovider_add">
                <div class="form-group">
                    <label class="col-sm-1 control-label">分润名称</label>
                    <div class="col-xs-6">
                         <input type="text" class="form-control required" name="name" placeholder="分润名称" value="<?php echo $user->name;?>"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">手续费率</label>
                    <div class="col-xs-6">
                         <input type="text" class="form-control required number" disabled="disabled" name="beizhu" value="<?php echo $beizhu;?>"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">采购商比率</label>
                    <div class="col-xs-3">
                         <input type="text" class="form-control required number" name="purchaser" placeholder="采购省代比率" value="<?php echo $user->purchaser;?>"/>
                    </div>
                    <div class="col-xs-3">
                         <input type="text" class="form-control queryid" data-name="purchaser_id" placeholder="采购省代用户名或手机号" value="<?php echo $nameArr['purchaser_id'];?>"/>
                         <input type="hidden" class="purchaser_id" name="purchaser_id" value="<?php echo $user->purchaser_id;?>"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">一级代理商比率</label>
                    <div class="col-xs-3">
                         <input type="text" class="form-control required number" name="manager_l1" placeholder="一级代理商比率" value="<?php echo $user->manager_l1;?>"/>
                    </div>
                    <div class="col-xs-3">
                         <input type="text" class="form-control queryid" data-name="manager_l1_id" placeholder="一级代理用户名或手机号" value="<?php echo $nameArr['manager_l1_id'];?>"/>
                         <input type="hidden" class="manager_l1_id" name="manager_l1_id" value="<?php echo $user->manager_l1_id;?>"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">二级代理商比率</label>
                    <div class="col-xs-3">
                         <input type="text" class="form-control required number" name="manager_l2" placeholder="二级代理商比率" value="<?php echo $user->manager_l2;?>"/>
                    </div>
                    <div class="col-xs-3">
                         <input type="text" class="form-control queryid" data-name="manager_l2_id" placeholder="二级代理用户名或手机号" value="<?php echo $nameArr['manager_l2_id'];?>"/>
                         <input type="hidden" class="manager_l2_id" name="manager_l2_id" value="<?php echo $user->manager_l2_id;?>"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">发展商比率</label>
                    <div class="col-xs-3">
                         <input type="text" class="form-control required number" name="growth" placeholder="发展商比率" value="<?php echo $user->growth;?>"/>
                    </div>
                    <div class="col-xs-3">
                         <input type="text" class="form-control queryid" data-name="growth_id" placeholder="发展商用户名或手机号" value="<?php echo $nameArr['growth_id'];?>"/>
                         <input type="hidden" class="growth_id" name="growth_id" value="<?php echo $user->growth_id;?>"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">分销商比率</label>
                    <div class="col-xs-3">
                         <input type="text" class="form-control required number" name="seller" placeholder="分销商比率" value="<?php echo $user->seller;?>"/>
                    </div>
                    <div class="col-xs-3">
                         <input type="text" class="form-control queryid" data-name="seller_id" placeholder="分销商用户名或手机号" value="<?php echo $nameArr['seller_id'];?>"/>
                         <input type="hidden" class="seller_id" name="seller_id" value="<?php echo $user->seller_id;?>"/>
                    </div>
                </div>
                <input type="hidden" name="rate_id" value="<?php echo $user->rate_id;?>" />
                <div class="form-btn">
                    <a href="javascript:;">
                        <button class="btn btn-info" >保存</button>
                    </a>
                    <a href="<?php echo site_url('tourismprofitrate/grid');?>">返回上一步</a>
                </div>
            </form>
        </div>
    </div>
</div>
<?php $this->load->view('layout/footer');?>
<script type="text/javascript">
$(function(){
    $('.form-btn').on('click', 'a', function(event){
        $('form#tourismprovider_add').submit(function(e){
            e.preventDefault();
        }).validate({
             submitHandler:function(form) {
                 $.ajax({
                    type:'post',
                    url:hostUrl()+'/tourismprofitrate/editPost',
                    data:$('form#tourismprovider_add').serialize(),
                    async:false,
                    dataType:'json',
                    beforeSend:function(){
                        $('.form-btn button').attr('disabled',true); 
                    },
                    success:function(data) {
                        if (data.status) {
                            layerMessages(data.status);
                            setTimeout(function(){
                                location.href = data.msg;
                            }, 2000);
                        } else {
                            layerMessages(data.status, data.msg);
                            $('.form-btn button').attr('disabled',false); 
                        }
                    }
                 })
            }
        });
        event.stopPropagation();
    });
    $('.queryid').change(function(){
        var name = $(this).attr('data-name');
        $.ajax({
            type:'post',
            url:hostUrl()+'/tourismprofitrate/ajaxQueryId',
            data:{namephone:$(this).val()},
            async:false,
            dataType:'json',
            success:function(data) {
                if (data.status) {
                    $('[class='+name+']').val(data.data.id);
                } else {
                    $('[class='+name+']').val(0);
                    layerMessages(data.status, data.msg);
                }
            }
         });
    });
});
</script>